﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Lib.Utils;
using Lib.Bases;

namespace MS.INV.MainData
{
    public partial class Customer_New : Lib.Bases.Forms.FBaseEdit
    {
        SysObj.L_KhachHang cls = new SysObj.L_KhachHang();

        public Customer_New(int _ObjID)
        {
            InitializeComponent();

            cbNhom.BaseList = new SysLst.L_KH_Nhom();
            cbLoai.BaseList = new SysLst.L_KH_Loai();

            this._BaseClass = cls;

            this.ObjID = _ObjID;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                if (this.ObjID > 0)
                {
                    cls.IdKhachHang = ObjID;
                    cls.ReadData();

                    txtMa.Text = cls.MaKhachHang;
                    txtTen.Text = cls.TenKhachHang;
                    txtDC.Text = cls.DiaChi;
                    txtFax.Text = cls.Fax;
                    txtMST.Text = cls.MST;
                    txtDT1.Text = cls.DienThoai1;
                    txtDT2.Text = cls.DienThoai2;
                    txtGhiChu.Text = cls.GhiChu;

                    cbLoai.EditValue = cls.IdLoai;
                    cbNhom.EditValue = cls.IdNhom;

                    btnUpdate.Enabled = true;
                }
                else
                    T_NewItemClick(null, null);
            }
            catch (Exception ex)
            {
                Lib.Bases.SysError.RaiseError(ex, this.Name, "OnLoad");
            }
        }

        public override void T_NewItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            base.T_NewItemClick(sender, e);
        }

        public override void T_UpdateItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (!Ctrls.CheckAllowNull(this))
                    return;
                cls.MaKhachHang = txtMa.Text;
                cls.TenKhachHang = txtTen.Text;
                cls.DiaChi = txtDC.Text;
                cls.Fax = txtFax.Text;
                cls.MST = txtMST.Text;
                cls.DienThoai1 = txtDT1.Text;
                cls.DienThoai2 = txtDT2.Text;
                cls.GhiChu = txtGhiChu.Text;

                cls.IdLoai = Cvert.ToInt32(cbLoai.EditValue, 0);
                cls.IdNhom = Cvert.ToInt32(cbNhom.EditValue, 0);

                base.T_UpdateItemClick(sender, e);
            }
            catch (Exception ex)
            {
                Lib.Bases.SysError.RaiseError(ex, this.Name, "Update data");
            }
        }
    }
}
